package com.hp.sso.service;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import com.hp.authweb.model.RoleInfo;
import com.hp.authweb.model.UserInfo;
import com.hp.authweb.repository.UserRepository;

@Service
public class SocialService {
	
	
	@Autowired
	private UserRepository userRepository;
	
	@Autowired
	private PasswordEncoder passwordEncoder;
	
	private final static String DEFAULATEPW="888888";

	
	@Transactional
	public UserInfo creatUser(String providerId){
		//三方登录只保存基本信息
		String userAccount=providerId;
		UserInfo user = new UserInfo();
		user.setAccount(userAccount);
		user.setPassword(passwordEncoder.encode(DEFAULATEPW));
		user.setDepartmentCode("HP00000000");
		user.setRealName("游客"+userAccount);
		List<RoleInfo>  list = new ArrayList<RoleInfo>();
		RoleInfo r =new RoleInfo();
		r.setId(1L);
		list.add(r);
		user.setRoleList(list);
		user = userRepository.save(user);
		
		return user;
	}
	
	
}
